package co.yixiang.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * @author ：LionCity
 * @date ：Created in 2020-08-04 16:55
 * @description：分页参数返回
 * @modified By：
 * @version: V1.0
 */
@Data
@Accessors(chain = true)
public class PageResult<T> implements Serializable {


    @ApiModelProperty("总数量")
    private long totalElements;

    @ApiModelProperty("内容")
    private List<T> content;

    public PageResult(long totalElements, List<T> content) {
        this.totalElements = totalElements;
        this.content = content;
    }

    public PageResult() {
    }

    public static <T> PageResultBuilder<T> builder() {
        return new PageResultBuilder<T>();
    }

    public static class PageResultBuilder<T> {
        private long totalElements;
        private List<T> content;

        PageResultBuilder() {
        }

        public PageResultBuilder<T> totalElements(long totalElements) {
            this.totalElements = totalElements;
            return this;
        }

        public PageResultBuilder<T> content(List<T> content) {
            this.content = content;
            return this;
        }

        public PageResult<T> build() {
            return new PageResult<T>(totalElements, content);
        }

        public String toString() {
            return "PageResult.PageResultBuilder(totalElements=" + this.totalElements + ", content=" + this.content + ")";
        }
    }
}
